 #include <stdio.h>
#include <sys/types.h>
#include <sys/wait.h>
#include <unistd.h>
#include <stdlib.h>

int main()
{
    pid_t pid;
    pid=fork();
    if(pid<0)
    {
         printf("%s fork error\n",__FUNCTION__);
         return 1;
    }
    else if(pid==0)
    {
        printf("child is run,pid is :%d\n",getpid());
        sleep(10);
        exit(252);
    }
    else 
    {
        int status=0;
        pid_t ret=waitpid(-1,&status,0);  // -1 等待任意子进程 option设置为0 表示阻塞式等待
        printf("this is test for wait\n");
        if(WIFEXITED(status) && ret==pid)
        {
            printf("wait child 5s succes,child return code is: %d.\n", WEXITSTATUS(status));
        }
        else 
        {
            printf("wait child failed, return %d .\n",WTERMSIG(status));
            return 1;
        }
    }
    
    return 0;
}
